package com.dragon.concurrent.demo.priority;

/**
 * 守护线程
 *
 * @author dragon
 * @version V1.0.0-RELEASE
 * @date 2019/6/1 20:10
 */
public class PriorityDemo {

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            int count = 0;
            while (true) {
                synchronized (PriorityDemo.class) {
                    count++;
                    if (count > 10000000) {
                        System.out.println("HighPriority is complete");
                        break;
                    }
                }
            }
        }, "highPriority");

        Thread t2 = new Thread(() -> {
            int count = 0;
            while (true) {
                synchronized (PriorityDemo.class) {
                    count++;
                    if (count > 10000000) {
                        System.out.println("lowPriority is complete");
                        break;
                    }
                }
            }
        }, "lowPriority");

        t1.setPriority(Thread.MAX_PRIORITY);
        t2.setPriority(Thread.MIN_PRIORITY);
        t2.start();
        t1.start();
    }
}
